﻿using System.Linq;
using INHollandair.Data;

namespace INHollandair.Core.Repositories
{
    public class EventLogRepository
    {
        private readonly PresentatieDBDataContext _context = new PresentatieDBDataContext();

        public IQueryable<Models.EventLog> EventLogRepo
        {
            get
            {
                return _context.EventLogs.Select(x => new Models.EventLog
                {
                    Id = x.Id,
                    Description = x.Description,
                    DateLogged = x.DateLogged
                });
            }
        }

        public void InsertEventLog(Models.EventLog eventLog)
        {
            EventLog eventLogToInsert = new EventLog
            {
                Id = eventLog.Id,
                Description = eventLog.Description,
                DateLogged = eventLog.DateLogged
            };

            _context.EventLogs.InsertOnSubmit(eventLogToInsert);
            _context.SubmitChanges();
        }
        public void UpdateEventLog(Models.EventLog eventLog)
        {
            EventLog eventLogToUpdate = _context.EventLogs.First(x => x.Id.Equals(eventLog.Id));
            eventLogToUpdate.Id = eventLog.Id;
            eventLogToUpdate.Description = eventLog.Description;
            eventLogToUpdate.DateLogged = eventLog.DateLogged;

            _context.SubmitChanges();
        }
        public void RemoveEventLog(Models.EventLog eventLog)
        {
            EventLog eventLogToRemove = _context.EventLogs.First(x => x.Id.Equals(eventLog.Id));
            _context.EventLogs.DeleteOnSubmit(eventLogToRemove);
            _context.SubmitChanges();
        }
    }
}
